package com.kai.service.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kai.service.data.PagingResult;
import com.kai.service.data.Result;
import com.kai.service.enums.ResultCodeEnum;

import java.util.List;

public class ResultResponseUtil {

    public static <T> Result<T> fail(ResultCodeEnum resultCode) {
        return fail(resultCode.getCode(), resultCode.getMessage());
    }

    public static <T> Result<T> fail(int code, String message) {
        return new Result<>(code, message, false);
    }

    public static <T> Result<T> success() {
        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(), true);
    }

    public static<T> Result<T> success(T data) {
        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(), true, data);
    }

    public static <T> PagingResult<T> pageSuccess(IPage<T> body) {
        return pageSuccess(body.getRecords(), body.getCurrent(), body.getSize(), body.getTotal());
    }

    public static <T> PagingResult<T> pageSuccess(List<T> body, long pageIndex, long pageSize, long total) {
        return new PagingResult<>(body, pageIndex, pageSize, total);
    }

}